
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package nac.firefight;

//~--- non-JDK imports --------------------------------------------------------

import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.DynamicShape;

import org.newdawn.slick.Image;

/**
 *
 * @author User
 */
public class Sprite extends Body {
    private Image[] images = new Image[1];


    public Sprite(Image[] images, String name, DynamicShape shape, float m) {
        super(name, shape, m);
        this.images = images;
    }

     public Sprite(Image image, String name, DynamicShape shape, float m) {
        super(name, shape, m);
        this.images[0] = image;
    }
   
    public Image getImage(int i) {
        return images[i];
    }
    
    public void rotate(float radian, int delta) {
        adjustRotation(radian * delta);
    }

    public void move(float speed, float radian, int delta) {
        float hip = speed * delta;
        float x   = +(float) (hip * Math.sin(radian));
        float y   = -(float) (hip * Math.cos(radian));

        adjustPosition(new Vector2f(x, y));
    }

    public void moveForward(float speed, int delta) {
        move(speed, getRotation(), delta);
    }

    public void moveRear(float speed, int delta) {
        move(speed, getRotation() + (float) Math.PI, delta);
    }

    public void flankLeft(float speed, int delta) {
        move(speed, getRotation() - (float) (Math.PI / 2), delta);
    }

    public void flankRight(float speed, int delta) {
        move(speed, getRotation() + (float) (Math.PI / 2), delta);
    }

    public void draw() {
        images[0].drawCentered(getPosition().getX(), getPosition().getY());
        images[0].setRotation((float) Math.toDegrees(getRotation()));
    }
    public void drawByIndex(int i){
        images[i].drawCentered(getPosition().getX(), getPosition().getY());
        images[i].setRotation((float) Math.toDegrees(getRotation()));
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
